argparser-rs
A simple argument parser, meant to parse command line input. It is inspired by the Python ArgumentParser
Simple class to parse arguments. The Highlights are:
- A configurable
add_opt
method, to tell it what to look for. - A generic
get
method, which will return the argument you want with any type that implementsFromStr
. - The arguments are stored in maps, and so are accessed by the name you give them in the
add_opt
method. - The
parse
method can be called on anIterator
that produces&String
s. - There are no static or global variables so you can have as many parsers as you want.
- The parser can take any values that implement
FromStr
or for which you can provide a closure to parse them from String - You can specify if any argument is required or not, as well as default values for all
- It also prints a default help message, similar to the one Python's argparser prints
Example use:
extern crate argparse;
use HashMap;
use ;
const LONG_STR: &'static str = r#"Check your proxy settings or contact your network administrator to make sure the proxy server is working. If you don't believe you should be using a proxy server: Go to the Chromium menu > Settings > Show advanced settings... > Change proxy settings... and make sure your configuration is set to "no proxy" or "direct.""#;
Terminal Output:
socks:Some("Monday:true Friday:false ")
length:Some("-60")
frequencies:Some("1 2 3 4 5 ")
height:Some("-6001.45e-2")
help:Some("true")
name:Some("Johnny")
mao:Some("true")
Usage: ./argparse [--socks k:v k2:v2...] [--length LENGTH] [--frequencies FREQUENCIES...] [--height HEIGHT] [--help ] [--name NAME] [--mao ]
Options:
--socks (-s) Required: false Type: Dict
If you wear socks that day
--length (-l) Required: true Type: Option
Check your proxy settings or contact your network administrator
to make sure the proxy server is working. If you don't believe
you should be using a proxy server: Go to the Chromium menu >
Settings > Show advanced settings... > Change proxy settings...
and make sure your configuration is set to "no proxy" or "direct."
--frequencies (-f) Required: false Type: List
User's favorite frequencies
--height (-h) Required: true Type: Option
Height of user in centimeters
--help (-h) Required: false Type: Flag
Show this help message
--name (-n) Required: true Type: Option
Name of user
--mao (-m) Required: false Type: Flag
Is the User Chairman Mao?